/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */
package cn.hermit.data.xml.model;

import java.io.Serializable;

import cn.hermit.util.OSUtils;

/**
 * Abstract class of XML objects. It's a parent class of all XML objects.
 * <p>
 * Any XML objects such like XML element, XML attribute, XML text node can be treated 
 * as a common XML node.
 * </p>
 * 
 * @author Jack Gao (Chinese name : GAO JIANGUO, Email : linux.gjg@gmail.com)
 * @date 19 Jun, 2014
 * 
 */
public abstract class XmlNode implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1139761230052350812L;

	XmlElement parent;

	XmlNode() {
	}

	/**
	 * Format XML string with tab indents.
	 * 
	 * @param depth
	 * 		number of tab indents
	 * @return
	 * 		Formatted XML string
	 */
	public String toFormatString(int depth) {
		return toFormatString(depth, OSUtils.NEW_LINE_FEED_DEFAULT);
	}

	/**
	 * Format XML string with tab indents.
	 * 
	 * @param depth
	 * 		Number of tab indents
	 * @param newLineFeed
	 * 		New line break
	 * @return
	 * 		Formatted XML string
	 */
	public String toFormatString(int depth, String newLineFeed) {
		return toFormatString(depth, newLineFeed, true);
	}
	
	/**
	 * Format XML string with tab indents.
	 * 
	 * @param depth
	 * 		number of tab indents
	 * @param newLineForTexts
	 * 		If true, will handle new line break in text nodes
	 * @return
	 * 		Formatted XML string
	 */
	public String toFormatString(int depth, boolean newLineForTexts) {
		return toFormatString(depth, OSUtils.NEW_LINE_FEED_DEFAULT, newLineForTexts);
	}

	/**
	 * Format XML string with tab indents.
	 * 
	 * @param depth
	 * 		number of tab indents
	 * @param newLineFeed
	 * 		New line break
	 * @param newLineForTexts
	 * 		If true, will handle new line break in text nodes
	 * @return
	 * 		Formatted XML string
	 */
	public abstract String toFormatString(int depth, String newLineFeed,
			boolean newLineForTexts);

	/**
	 * @return The parent of XML node
	 */
	public XmlElement getParent() {
		return parent;
	}

	/**
	 * Check if the XML node is Document.
	 * 
	 * @return
	 */
	public abstract boolean isDocument();

	/**
	 * Check if the XML node is Element.
	 * 
	 * @return
	 */
	public abstract boolean isElement();

	/**
	 * Check if the XML node is Attribute.
	 * 
	 * @return
	 */
	public abstract boolean isAttribute();

	/**
	 * Check if the XML node is Text.
	 * 
	 * @return
	 */
	public abstract boolean isText();

	/**
	 * Check if the XML node is Text with string content.
	 * 
	 * @return
	 */
	public abstract boolean isPureText();

	/**
	 * Check if the XML node is CDATA.
	 * 
	 * @return
	 */
	public abstract boolean isCdata();

	/**
	 * Check if the XML node is Comment.
	 * 
	 * @return
	 */
	public abstract boolean isComment();

	/**
	 * Check if the XML node is Header.
	 * 
	 * @return
	 */
	public abstract boolean isHeader();

	/**
	 * Check if the node has QName.
	 * 
	 * @return
	 */
	public abstract boolean isNameNode();

}